<?php

namespace app\controller\admin;

use app\common\model\Admin;
use app\common\model\Authentication;
use app\common\service\AuthenticationService;
use app\common\service\UserService as Service;
use app\common\util\Result;
use think\annotation\route\Group;
use think\annotation\route\Post;
use think\annotation\route\Route;

/**
 * 管理员 控制器类
 */
#[Group('admin/authentication')]
class AuthenticationController extends AdminAuthorizedController
{
    //权限前缀
    protected string $power_prefix = "Authentication";

    /**
     * 初始化业务
     * @return Service
     */
    protected function initService()
    {
        return new Service($this->app);
    }

    #[Route('GET|POST', 'admin_init')]
    public function adminInit(Admin $admin)
    {
        $result["isPassList"]=Authentication::getIsPassList();
        return Result::success($result);
    }

    /**
     * 后台分页
     * @param Admin $admin
     * @return \think\Paginator
     */
    #[Route('GET|POST', 'page')]
    public function page(Admin $admin)
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'index');
        return (new AuthenticationService(app()))->adminPage(request()->param(),$admin);
    }

    #[Route('GET|POST', 'pass')]
    public function pass(Admin $admin): \app\common\util\Result
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'pass');
        return (new AuthenticationService(app()))->pass(request()->param());
    }

    #[Route('GET|POST', 'detail')]
    public function detail(Admin $admin): \app\common\util\Result
    {
        $this->checkPower($admin, $this->power_prefix . '_' . 'index');
        $rule = [
            "user_id" => "require"
        ];
        $param = request()->param();
        $this->validate($param, $rule);
        return AuthenticationService::instance()->detailByUserId($param["user_id"]);
    }
}
